const fp = require('lodash/fp');
const {Maybe, Container} = require('./04SupportJs');

//practice 01

let maybe = Maybe.of([5, 6, 1]);
let ex1 = (container, addedvalue) => {
  //container is functor
  container._value = fp.map(item => fp.add(addedvalue, item), container._value);
}
ex1(maybe, 3);
console.log(maybe._value);
ex1(maybe, 4);
console.log(maybe._value);

//practice 02
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = (container) => {
  return fp.first(container._value);
}
console.log(ex2(xs));

//practice 03
let safeProp = fp.curry(function(x, o){
  return Maybe.of(o[x]);
})
let user = {id: 2, name: 'Albert'};
let ex3 = (item) => {
   let getName = safeProp('name');
   let name = getName(item);
   name = name.map(fp.flowRight(fp.first, Array.from)) //Array.from(name._value);
   return(name._value);
}
console.log(ex3(user));

//practice 04
let ex4 = function (n) {
  let container = Maybe.of(n);
  let intcontainer = container.map(parseInt);
  return intcontainer._value;
}
console.log(ex4("121"));